import io.netty.channel.DefaultChannelId;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.MessageQueueSelector;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * @author songxz
 * @date 2022/8/29
 */
public class ProducerOrder01 {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("hello_group");
        DefaultChannelId.newInstance();
        producer.setNamesrvAddr("localhost:9876");

        producer.start();

        String body =  " Hello RocketMQ " + 1;
        Message msg = new Message("TopicTest", "TagA", body.getBytes());
        producer.sendOneway(msg, new MessageQueueSelector() {
            @Override
            public MessageQueue select(List<MessageQueue> list, Message message, Object arg) {
                int index = (int) arg;
                return list.get(index);
            }
        },1);
        producer.shutdown();
    }
}
